//
//  FlightView.swift
//  ImGuider X
//
//  Created by 王鹏宇 on 9/29/18.
//  Copyright © 2018 imguider. All rights reserved.
//

import UIKit

class FlightView: UIView {
    
    var  flightLineView : UIImageView!
    var  currentCityLabel : UILabel!
    var  destinationLabel : UILabel!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setup()
    }
    
    func configData(model : AirplaneDetailModel?){
        
        self.currentCityLabel?.text = model?.departureCity
        self.destinationLabel?.text = model?.arrivalCity
    }
    
    private func setup() {
        
        flightLineView = UIImageView(image: UIImage(named: "flightLine"))
        
        self.addSubview(flightLineView!)
        
        flightLineView?.snp.makeConstraints {
            
            [weak self] make in
            guard let `self` = self else { return }
            
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-10)
            make.width.equalToSuperview().multipliedBy(2.0 / 3.0)
            make.height.equalTo(self.flightLineView.snp.width).multipliedBy(1.0 / 4.0)
        }
        
        currentCityLabel = UILabel()
        currentCityLabel?.textColor = UIColor.white
        currentCityLabel?.textAlignment = .center
        currentCityLabel?.font = UIFont.systemFont(ofSize: 14)
        currentCityLabel?.text = "上海"
        self.addSubview(currentCityLabel!)
        currentCityLabel?.snp.makeConstraints({
            
            [weak self] make in
            guard let `self` = self else { return }
            make.top.equalTo(self.flightLineView.snp.bottom).offset(5)
            make.centerX.equalTo(self.flightLineView.snp.left).offset(10)
        })
        
        destinationLabel = UILabel()
        destinationLabel?.textColor = UIColor.white
        destinationLabel?.textAlignment = .center
        destinationLabel?.font = UIFont.systemFont(ofSize: 14)
        destinationLabel?.text = "巴黎"
        self.addSubview(destinationLabel!)
        destinationLabel?.snp.makeConstraints({
            [weak self] make in
            guard let `self` = self else { return }
            
            make.top.equalTo(self.flightLineView.snp.bottom).offset(5)
            make.centerX.equalTo(self.flightLineView.snp.right).offset(-8)
        })
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

